package com.esri.core.portal;

import java.util.LinkedHashMap;
import java.util.Map;

/* loaded from: classes.dex */
public class PortalQueryParams {
    boolean a;
    String b;
    String c;
    PortalQuerySortOrder d;
    int e;
    int f;

    /* loaded from: classes.dex */
    public enum PortalQuerySortOrder {
        ASCENDING { // from class: com.esri.core.portal.PortalQueryParams.PortalQuerySortOrder.1
            @Override // java.lang.Enum
            public String toString() {
                return "asc";
            }
        },
        DESCENDING { // from class: com.esri.core.portal.PortalQueryParams.PortalQuerySortOrder.2
            @Override // java.lang.Enum
            public String toString() {
                return "desc";
            }
        }
    }

    public PortalQueryParams() {
        this.a = true;
        this.e = 1;
        this.f = 10;
        this.d = PortalQuerySortOrder.ASCENDING;
    }

    public PortalQueryParams(String str) {
        this();
        setQuery(str);
    }

    public PortalQueryParams(String str, int i) {
        this(str);
        this.f = i;
    }

    public PortalQueryParams withNextStart(int i) {
        if (i < 0) {
            return null;
        }
        PortalQueryParams portalQueryParams = new PortalQueryParams();
        portalQueryParams.b = this.b;
        portalQueryParams.f = this.f;
        portalQueryParams.c = this.c;
        portalQueryParams.d = this.d;
        portalQueryParams.e = i;
        portalQueryParams.a = this.a;
        return portalQueryParams;
    }

    public PortalQueryParams setQueryForItemsInGroup(String str) {
        return setQuery(null, str, null);
    }

    public PortalQueryParams setQueryForGroups(String str, String str2) {
        StringBuilder sb = new StringBuilder();
        if (str != null && !"".equals(str)) {
            sb.append("owner:\"");
            sb.append(str);
            sb.append("\"");
        }
        if (str2 != null && !"".equals(str2)) {
            if (sb.length() > 0) {
                sb.append(" AND ");
            }
            sb.append("title:\"");
            sb.append(str2);
            sb.append("\"");
        }
        if (sb.length() > 0) {
            this.b = sb.toString();
        }
        return this;
    }

    public PortalQueryParams setQuery(PortalItemType portalItemType, String str, String str2) {
        StringBuilder sb = new StringBuilder();
        if (portalItemType != null) {
            if (portalItemType.equals(PortalItemType.WEBMAP)) {
                sb.append("+type:\"");
                sb.append(portalItemType.toString());
                sb.append("\" -type:\"");
                sb.append(PortalItemType.WEB_MAPPING_APPLICATION);
                sb.append("\"");
            } else if (portalItemType.equals(PortalItemType.FEATURE_COLLECTION)) {
                sb.append("+type:\"");
                sb.append(portalItemType.toString());
                sb.append("\" -type:\"");
                sb.append(PortalItemType.FEATURE_COLLECTION_TEMPLATE);
                sb.append("\"");
            } else {
                sb.append("type:\"");
                sb.append(portalItemType.toString());
                sb.append("\"");
            }
        }
        if (str != null && !"".equals(str)) {
            if (sb.length() > 0) {
                sb.append(" AND ");
            }
            sb.append("group:");
            sb.append(str);
        }
        if (str2 != null && !"".equals(str2)) {
            boolean z = false;
            if (sb.length() > 0) {
                sb.append(" AND (");
                z = true;
            }
            sb.append(str2);
            if (z) {
                sb.append(')');
            }
        }
        if (sb.length() <= 0) {
            sb.append("uploaded: [0000000000000000000 TO 000000" + System.currentTimeMillis() + "000] -type:\"Code Attachment\" -type:\"Service Definition\" -type:\"Featured Items\" -type:\"Symbol Set\" -type:\"Color Set\" -type:\"Feature Collection\"");
        }
        if (sb.length() > 0) {
            this.b = sb.toString().replace("\\\"", "\"");
        }
        return this;
    }

    public PortalQueryParams setQueryForItemWithId(String str) {
        StringBuilder sb = new StringBuilder();
        if (str != null && !"".equals(str)) {
            sb.append("id:");
            sb.append(str);
        }
        if (sb.length() > 0) {
            this.b = sb.toString();
        }
        return this;
    }

    public Map<String, String> generateRequestParams() {
        return generateRequestParams(null, false);
    }

    public Map<String, String> generateRequestParams(String str, boolean z) {
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        String str2 = this.b;
        if (str2 != null && !"".equals(str2)) {
            if (str != null && str.trim().length() > 0) {
                StringBuilder sb = new StringBuilder(this.b);
                sb.append(z ? " AND accountid:" : " AND orgid:");
                sb.append(str);
                linkedHashMap.put("q", sb.toString());
            } else {
                linkedHashMap.put("q", this.b);
            }
        }
        linkedHashMap.put("sortOrder", this.d.toString());
        linkedHashMap.put("num", String.valueOf(this.f));
        linkedHashMap.put("start", String.valueOf(this.e));
        String str3 = this.c;
        if (str3 != null) {
            linkedHashMap.put("sortField", str3);
        }
        return linkedHashMap;
    }

    public String getQuery() {
        return this.b;
    }

    public PortalQueryParams setQuery(String str) {
        return setQuery(null, null, str);
    }

    public String getSortField() {
        return this.c;
    }

    public PortalQueryParams setSortField(String str) {
        this.c = str;
        return this;
    }

    public PortalQuerySortOrder getSortOrder() {
        return this.d;
    }

    public PortalQueryParams setSortOrder(PortalQuerySortOrder portalQuerySortOrder) {
        this.d = portalQuerySortOrder;
        return this;
    }

    public int getStartIndex() {
        return this.e;
    }

    public PortalQueryParams setStartIndex(int i) {
        this.e = i;
        return this;
    }

    public int getLimit() {
        return this.f;
    }

    public PortalQueryParams setLimit(int i) {
        this.f = i;
        return this;
    }

    public int hashCode() {
        int i = (this.f + 31) * 31;
        String str = this.b;
        int hashCode = (i + (str == null ? 0 : str.hashCode())) * 31;
        String str2 = this.c;
        int hashCode2 = (hashCode + (str2 == null ? 0 : str2.hashCode())) * 31;
        PortalQuerySortOrder portalQuerySortOrder = this.d;
        return ((hashCode2 + (portalQuerySortOrder != null ? portalQuerySortOrder.hashCode() : 0)) * 31) + this.e;
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj != null && (obj instanceof PortalQueryParams)) {
            PortalQueryParams portalQueryParams = (PortalQueryParams) obj;
            if (this.f != portalQueryParams.f) {
                return false;
            }
            String str = this.b;
            if (str == null) {
                if (portalQueryParams.b != null) {
                    return false;
                }
            } else if (!str.equals(portalQueryParams.b)) {
                return false;
            }
            String str2 = this.c;
            if (str2 == null) {
                if (portalQueryParams.c != null) {
                    return false;
                }
            } else if (!str2.equals(portalQueryParams.c)) {
                return false;
            }
            return this.d == portalQueryParams.d && this.e == portalQueryParams.e;
        }
        return false;
    }

    public boolean isCanSearchPublic() {
        return this.a;
    }

    public void setCanSearchPublic(boolean z) {
        this.a = z;
    }

    public String toString() {
        return "PortalQueryParams [query=" + this.b + ", sortField=" + this.c + ", sortOrder=" + this.d + ", startIndex=" + this.e + ", limit=" + this.f + "]";
    }
}
